#include <iostream>
using namespace std;

/*
class sum{
public:
    sum(){
        _sum += _i;
        ++_i;
    }
    static int GetSum(){
        return _sum;
    }
private:
    static int _i;
    static int _sum;
};

int sum::_i = 1;
int sum::_sum = 0;

class Solution{
public:
    int Sum_Solution(int n){
        sum a[n];
        return sum::GetSum();
    }
};

int main() {
    cout << Solution().Sum_Solution(10) << endl;
    return 0;
}
*/

//打印日期
/*
int isLeapYear(int year){
    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        return 1;
    return 0;
}

int GetMonth(int year, int days){
    int monthArray[13] = {0,31,59,90,120,151,181,212,243,273,304,334,365};
    if (isLeapYear(year)){
        for (int i = 2; i < 13; ++i) {
            monthArray[i] += 1;
        }
    }
        //monthArray[13] = {0,31,60,91,121,152,182,213,244,274,305,335,366};
    int i = 0;
    while (days > monthArray[i])
        i++;
    return i;
}

int GetDate(int year, int month, int days){
    int monthArray[13] = {0,31,59,90,120,151,181,212,243,273,304,334,365};
    if (isLeapYear(year)){
        for (int i = 2; i < 13; ++i) {
            monthArray[i] += 1;
        }
    }
    int day = days - monthArray[month-1];
    return day;
}

int main(){
    int year = 2001, days = 60;
    while (scanf("%d%d",&year,&days) != EOF){
        int month = GetMonth(year,days);
        int day = GetDate(year,month,days);
        printf("%04d-%02d-%02d\n",year,month,day);
    }
}
*/

/*
int main()
{
    int year;
    int day;
    int mon[13] = {31, 28, 31, 30, 31, 30, 31, 31, 30 ,31, 30, 31};
    while(cin>>year>>day)
    {
        if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
            mon[1] = 29;
        else
            mon[1] = 28;
        for(int i = 0; i < 12; i++)
        {
            if(day <= mon[i])
            {
                printf("%04d-%02d-%02d\n", year, i + 1, day);
                break;
            }else
                day = day - mon[i];
        }
    }
    return 0;
}
*/

int GetYearDay(int year){
    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        return 366;
    return 365;
}

//日期累加
int GetMonthDay(int year, int month){
    int monthArray[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    if(month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400) == 0))
        return 29;
    else
        return monthArray[month];
}

int main(){
    int m = 0;
    int year = 2008, month = 2, day = 3,days = 100;
    cin >> m;
    while (m--){
        cin >> year >> month >> day >> days;
        day += days;
        while (day > GetMonthDay(year,month)){
            day -= GetMonthDay(year,month);
            month++;
            if (month == 13){
                year++;
                month = 1;
            }
        }
        printf("%04d-%02d-%02d\n",year,month,day);
    }
}
